package com.guie.kjzh.rest;

import me.zhengjie.annotation.Log;
import com.guie.kjzh.domain.Pay;
import com.guie.kjzh.service.PayService;
import com.guie.kjzh.service.dto.PayDto;
import com.guie.kjzh.service.dto.PayQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author simon
* @date 2022-02-24
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "kjzh：pay管理")
@RequestMapping("/api/pay")
public class PayController {

    private final PayService payService;

    @GetMapping
    @Log("查询kjzh：pay")
    @ApiOperation("查询kjzh：pay")
    @PreAuthorize("@el.check('pay:list')")
    public ResponseEntity query(PayQueryParam query, Pageable pageable){
        return new ResponseEntity<>(payService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增kjzh：pay")
    @ApiOperation("新增kjzh：pay")
    @PreAuthorize("@el.check('pay:add')")
    public ResponseEntity create(@Validated @RequestBody PayDto resources){
        return new ResponseEntity<>(payService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改kjzh：pay")
    @ApiOperation("修改kjzh：pay")
    @PreAuthorize("@el.check('pay:edit')")
    public ResponseEntity update(@Validated @RequestBody PayDto resources){
        payService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除kjzh：pay")
    @ApiOperation("删除kjzh：pay")
    @PreAuthorize("@el.check('pay:del')")
    public ResponseEntity delete(@RequestBody Set<Long> ids) {
        payService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出kjzh：pay")
    @ApiOperation("导出kjzh：pay")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('pay:list')")
    public void download(HttpServletResponse response, PayQueryParam query) throws IOException {
        payService.download(payService.queryAll(query), response);
    }*/

}
